5accb135178325878840c6e36fc3e640ae582dea,src/com/android/providers/downloads/Helpers.java,Helpers,isFilenameValid,#String#File#,346
Before Change
static boolean isFilenameValid(String filename, File downloadsDataDir) {
final String[] whitelist;
try {
filename = new File(filename).getCanonicalPath();
whitelist = new String[] {
downloadsDataDir.getCanonicalPath(),
Environment.getDownloadCacheDirectory().getCanonicalPath(),
Environment.getExternalStorageDirectory().getCanonicalPath(),
};
} catch (IOException e) {
Log.w(TAG, "Failed to resolve canonical path: " + e);
return false;
}
for (String test : whitelist) {
if (filename.startsWith(test)) {
return true;
}
}
After Change
static boolean isFilenameValid(Context context, File file) {
final File[] whitelist;
try {
whitelist = new File[] {
context.getFilesDir().getCanonicalFile(),
context.getCacheDir().getCanonicalFile(),
Environment.getDownloadCacheDirectory().getCanonicalFile(),
Environment.getExternalStorageDirectory().getCanonicalFile(),
};
} catch (IOException e) {
Log.w(TAG, "Failed to resolve canonical path: " + e);
return false;
}
for (File testDir : whitelist) {
if (contains(testDir, file)) {
return true;
}
}